<?php
/**
 * Created by PhpStorm.
 * User: cyc
 * Date: 2017/11/1
 * Time: 下午2:53
 */

class ApiTopicService extends ApiBaseService
{

//param | required | type   |describe
//----  |------    |------  |----
//sid  | true    |int     |分类id
//color  | false    |int     |是否返回描述的颜色默认为1 返回，可选值0 不返回
//page  | false    |int     |分页,默认为0
//size | false    |int     |分页大小，默认为3个

//                   {"id":1,"name":"每日大法好","avater":"http://tv.libooc.com/avater/topic/xxx.jpg","color":"#ffff"},

    public static function videosAction($params)
    {

        $tids = self::util_array_get($params, 'tid',null);
        if(!is_array($tids))
        {
            $tids = [$tids,];
        }
        $page = self::util_array_get($params, 'page', 0);
        $size = self::util_array_get($params, 'size', 3);
        $videos = [];
        foreach ($tids as $tid)
        {
            if ($topic = Topic::model()->findByAttributes(['id'=>$tid])) {
                $videos = [];
                foreach ($topic->getRealVideos($page,$size) as $video)
                {
                    $videos[] =['id' => $video->id, 'name' => $video->name,'avater'=>$video->avetar,];
                }
            }
        }
        return $videos;
    }

}